<!-- 新增模板文件（参考user/add.html结构） -->
<!DOCTYPE html>
<html>
<head>
    <title>新增产量数据</title>
    {% include 'system/common/header.html' %}
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-header">新增产量数据信息</div>
    <div class="layui-card-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">省份代码</label>
                <div class="layui-input-block">
                    <input type="text" name="province_code" lay-verify="required" placeholder="请输入省份代码"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">省份名称</label>
                <div class="layui-input-block">
                    <input type="text" name="province_name" lay-verify="required" placeholder="请输入省份名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">年份</label>
                <div class="layui-input-block">
                    <input type="text" name="year" lay-verify="required" placeholder="请输入年份" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">产量指标</label>
                <div class="layui-input-block">
                    <input type="text" name="indicator" lay-verify="required" placeholder="请输入受灾指标"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">产量面积</label>
                <div class="layui-input-block">
                    <input type="text" name="value" lay-verify="required" placeholder="请输入受灾面积（公顷）"
                           class="layui-input">
                </div>
            </div>

            <div class="button-container">
                <button type="submit" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="user-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>

</div>

</body>
{% include 'system/common/footer.html' %}

    <script>
        layui.use(['form', 'jquery', 'dtree'], function () {
            let form = layui.form
            let $ = layui.jquery
            form.on('submit(user-save)', function (data) {
                let roleIds = ''
                $('input[type=checkbox]:checked').each(function () {
                    roleIds += $(this).val() + ','
                })
                roleIds = roleIds.substr(0, roleIds.length - 1)
                data.field.roleIds = roleIds

                $.ajax({
                    url: '/agricultural/save',
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function (result) {
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
                                parent.layui.table.reload('user-table')
                            })
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000})
                        }
                    }
                })
                return false
            })
        })
    </script>
</html>

